#include "swpsimdecisiongraphicitem.h"

#include "graphicitemcommon.h"

using namespace core;
using namespace swp;

SwpSimDecisionGraphicItem::SwpSimDecisionGraphicItem(QGraphicsItem* parent) :
    SwpDecisionGraphicItem(parent), ISimItem(),
        m_isInSimPath(false),
        m_originId()
{
    setFlag(QGraphicsItem::ItemIsMovable, false);

    initProperties();
}

SwpSimDecisionGraphicItem::SwpSimDecisionGraphicItem(
    SwpDecisionGraphicItem* from,
        QGraphicsItem* parent) : SwpDecisionGraphicItem(parent), ISimItem(),
        m_isInSimPath(false),
        m_originId(from->id())
{
    setFlag(QGraphicsItem::ItemIsMovable, false);

    initProperties();

    setPos(from->pos());    
}

SwpSimDecisionGraphicItem::~SwpSimDecisionGraphicItem()
{

}

void SwpSimDecisionGraphicItem::initYesNo(SwpDecisionGraphicItem* from)
{
    SwpDecisionGraphicItem::propertyChanged(m_yesProp.Name,
        from->propertyValue(m_yesProp.Name).toList().first(), true);
    SwpDecisionGraphicItem::propertyChanged(m_noProp.Name,
        from->propertyValue(m_noProp.Name).toList().first(), true);
    SwpDecisionGraphicItem::propertyChanged(m_labelPositionProp.Name,
        from->propertyValue(m_labelPositionProp.Name).toList().first(), true);
    SwpDecisionGraphicItem::propertyChanged(m_labelProp.Name,
        from->propertyValue(m_labelProp.Name), true);
}

bool SwpSimDecisionGraphicItem::supportsConnection(
        const ConnectionData& connection) const
{
    return connection.ConnectionId == CONNECTION_SIM_PATH;
}

int SwpSimDecisionGraphicItem::type() const
{
    return SWP_SIM_DECISION_ITEM;
}

IEditorItem* SwpSimDecisionGraphicItem::copy() const
{
    return new SwpSimDecisionGraphicItem();
}

bool SwpSimDecisionGraphicItem::isInSimPath() const
{
    return m_isInSimPath;
}

void SwpSimDecisionGraphicItem::setInSimPath(bool in)
{
    if (in)
    {
        setPen(QPen(m_palette->acceptsConnectionColor(), 2));
    }
    else
    {
        setPen(QPen(m_palette->borderColor(), 1));
    }

    m_isInSimPath = in;
}

QUuid SwpSimDecisionGraphicItem::originId() const
{
    return m_originId;
}

void SwpSimDecisionGraphicItem::initProperties()
{
    m_yesProp.setVisibleToEditor(false);
    m_noProp.setVisibleToEditor(false);
    m_labelProp.setVisibleToEditor(false);
    m_labelPositionProp.setVisibleToEditor(false);
}
